package com.itheima.demo02;

public class PersonTest {
    public static void main(String[] args) {
        //测试空参构造.
        //1. 通过多态的方式创建Manager类对象.
        Person m = new Manager();
        //2. 给属性赋值.
        m.setName("X-man");
        m.setId("001");
        m.setSalary(15000);
        //3.打印属性值
        System.out.println("name:" + m.getName() + ",ID:" + m.getId() + ",salary:" + m.getSalary());
        //4. 调用eat(),work(),sleep()
        m.eat();
        m.work();
        m.sleep();
        //5. 通过向下转型,访问bonus属性
        Manager m12 = (Manager) m;
        m12.setBonus(8888);
        System.out.println("name:" + m12.getName() + ",ID:" + m12.getId() + ",salary:" + m12.getSalary() + ",bonus:" + m12.getBonus());
        System.out.println("-----------------------------------");
        //测试全参构造.
        //1. 通过多态的方式创建Manager类对象.
        Person m2 = new Manager("X-man", "001", 15000);
        //3.打印属性值
        System.out.println("name:" + m2.getName() + ",ID:" + m2.getId() + ",salary:" + m2.getSalary());
        //4. 调用eat(),work(),sleep()
        m2.eat();
        m2.work();
        m2.sleep();
        //5. 通过向下转型,访问bonus属性
        Manager m22 = (Manager) m;
        m22.setBonus(8888);
        System.out.println("name:" + m22.getName() + ",ID:" + m22.getId() + ",salary:" + m22.getSalary() + ",bonus:" + m22.getBonus());
        System.out.println("-----------------------------------");

        //测试空参构造.
        //1. 通过多态的方式创建Coder类对象.
        Person c = new Coder();
        //2. 给属性赋值.
        c.setName("X-coderMan");
        c.setSalary(12888);
        c.setId("002");
        //3.打印属性值
        System.out.println("name:" + c.getName() + ",ID:" + c.getId() + ",salary:" + c.getSalary());
        //4. 调用eat(),work(),sleep()
        c.eat();
        c.work();
        c.sleep();
        //5. 通过向下转型.
        Coder c1 = (Coder) c;
        System.out.println("name:" + c1.getName() + ",ID:" + c1.getId() + ",salary:" + c1.getSalary());
        System.out.println("-----------------------------------");

        //测试全参构造.
        //1. 通过多态的方式创建Manager类对象.
        Person c2 = new Coder("X-coderMan", "002", 15000);
        //3.打印属性值
        System.out.println("name:" + c2.getName() + ",ID:" + c2.getId() + ",salary:" + c2.getSalary());
        //4. 调用eat(),work(),sleep()
        c2.eat();
        c2.work();
        c2.sleep();
        //5. 通过向下转型,访问属性.
        Coder c22 = (Coder) c2;
        System.out.println("name:" + c22.getName() + ",ID:" + c22.getId() + ",salary:" + c22.getSalary());
        System.out.println("-----------------------------------");
    }
}
